﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Security.Permissions;
using System.Text;

namespace MedReg.Classes
{
    [Serializable]
    public class RegistrationType : ISerializable
    {
        private int idField;

        private string nameField;

        private static readonly RegistrationType theOneObject = new RegistrationType();

        public static RegistrationType RegistrationTypel()
        {
            return theOneObject;
        }
        /// <remarks/>
        public int ID
        {
            get
            {
                return this.idField;
            }
            set
            {
                this.idField = value;
            }
        }

        /// <remarks/>
        public string Name
        {
            get
            {
                return this.nameField;
            }
            set
            {
                this.nameField = value;
            }
        }
         [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.SerializationFormatter)]
        public void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            //throw new NotImplementedException();
            info.AddValue("ID", idField);
            info.AddValue("Name", nameField);
        }
        public RegistrationType()
        {
        }
        public List<Classes.RegistrationType> getRegistrationTypeList(List<Classes.AddressEntity> sAddressEntity)
        {

            var sRegistrationType = new List<Classes.RegistrationType>(from lv in sAddressEntity select lv.Registration);

            var ssSub = sRegistrationType
                .GroupBy(s => new { s.ID })
                //.GroupBy(s => new { s.ID, s.Name, s.Parent })
                .Select(g => g.First())
                .OrderBy(o => o.ID)
                .ToList();
            return ssSub;
        }
    }
}
